"""
@author: Tugba Eraslanoglu
Checking the data to map event area coordinates
"""
import pandas as pd
import geopandas as gpd
import folium
from pyproj import CRS
/tmp/ipykernel_188/394615755.py:9: UserWarning: Shapely 2.0 is installed, but because PyGEOS is also installed, GeoPandas will still use PyGEOS by default for now. To force to use and test Shapely 2.0, you have to set the environment variable USE_PYGEOS=0. You can do this before starting the Python process, or in your code before importing geopandas: import os os.environ['USE_PYGEOS'] = '0' import geopandas In a future release, GeoPandas will switch to using Shapely by default. If you are using PyGEOS directly (calling PyGEOS functions on geometries from GeoPandas), this will then stop working and you are encouraged to migrate from PyGEOS to Shapely 2.0 (https://shapely.readthedocs.io/en/latest/migration_pygeos.html). import geopandas as gpd
#Load the data and read
#data_file = "ACLED_newspaperdata.csv"
data_file = "newspaperdata.csv"
#df = pd.read_csv(data_file, delimiter=';')
df = pd.read_csv(data_file, sep='\t')
df.head()
| Unnamed: 0 | event_id | event_date | year | month | disorder_type | event_type | sub_event_type | actor1 | assoc_actor_1 | ... | population_5km | population_best | crowd_size_class | crowd_size_cat | crowd_size | crowd_size_w_n | with_vehicles | ? | split | notes11 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | DEU20172 | 2024-02-16 | 2024 | 2 | Demonstrations | Protests | Peaceful protest | Protesters (Germany) | NaN | ... | 138680 | 23736 | 3 | NaN | 100.0 | 100.0 | NaN | NaN | NaN | about 100 climate activists participated in a ... |
| 1 | 2 | DEU20173 | 2024-02-16 | 2024 | 2 | Demonstrations | Protests | Peaceful protest | Protesters (Germany) | NaN | ... | 138680 | 23736 | 6 | NaN | 1020.0 | 1020.0 | NaN | NaN | NaN | in the evening, about 1,000 people participate... |
| 2 | 3 | DEU20104 | 2024-02-15 | 2024 | 2 | Demonstrations | Protests | Protest with intervention | Protesters (Germany) | Last Generation (Germany) | ... | 138680 | 23736 | 1 | NaN | 3.0 | 3.0 | NaN | NaN | NaN | 3 Last Generation activists protested in the F... |
| 3 | 4 | DEU20126 | 2024-02-15 | 2024 | 2 | Demonstrations | Protests | Peaceful protest | Protesters (Germany) | Labor Group (Germany) | ... | 138680 | 23736 | 0 | NaN | 200.0 | NaN | NaN | NaN | NaN | actors and directors protested in Berlin - Mit... |
| 4 | 5 | DEU20100 | 2024-02-14 | 2024 | 2 | Demonstrations | Protests | Protest with intervention | Protesters (Germany) | NaN | ... | 127378 | 11620 | 4 | NaN | 280.0 | 280.0 | NaN | NaN | NaN | in the evening, about 230 pro-Palestine demons... |
5 rows × 40 columns
# Check the columns of the data
df.columns
Index(['Unnamed: 0', 'event_id', 'event_date', 'year', 'month',
'disorder_type', 'event_type', 'sub_event_type', 'actor1',
'assoc_actor_1', 'inter1', 'actor2', 'assoc_actor_2', 'inter2',
'interaction', 'civilian_targeting', 'admin2', 'location', 'latitude',
'longitude', 'source', 'source_scale', 'label', 'class', 'notes22',
'notes', 'fatalities', 'timestamp', 'population_1km', 'population_2km',
'population_5km', 'population_best', 'crowd_size_class',
'crowd_size_cat', 'crowd_size', 'crowd_size_w_n', 'with_vehicles', '?',
'split', 'notes11'],
dtype='object')
# Check the unique longitutude values of the data
df['longitude'].unique()
array([13.4024, 13.4403, 13.4354, 13.3738, 13.2317, 13.5876, 13.4951,
13.2639, 13.3459, 13.4105, 13.6006, 13.4031, 13.198 ])
# Check the unique latitude values of the data
df['latitude'].unique()
array([52.5177, 52.501 , 52.481 , 52.4406, 52.428 , 52.5223, 52.5197,
52.5079, 52.5711, 52.5244, 52.4175, 52.566 , 52.5356])
df['longitude'] = pd.to_numeric(df['longitude'])
df['latitude'] = pd.to_numeric(df['latitude'])
# Create a new GeoDataFrame
df_geo = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df['longitude'], df['latitude']))
# Set the CRS to WGS84 (EPSG:4326)
df_geo.crs = CRS("EPSG:4326")
# Create a Folium map centered around the mean latitude and longitude
osm_map = folium.Map(location=[df_geo['latitude'].mean(), df_geo['longitude'].mean()], zoom_start=4)
# Convert the GeoDataFrame to GeoJSON format
points = folium.features.GeoJson(df_geo.to_json())
# Add the GeoJSON data to the map
osm_map.add_child(points)
osm_map
Note: As it seen, the coordinates describe the just main locations not specific areas for each protest.